import {
  LOGIN_OK,
  LOGION_OUT,
  GET_USER_INFO,
  GET_USER_LIST
} from '../actionTypes'

const initState = {
  token: localStorage.getItem('token'),
  userinfo: {},
  userlist:[]
}

export default function reducer(state=initState, action) {
  let newState = JSON.parse(JSON.stringify(state))
  switch (action.type) {
    case LOGIN_OK:
      newState.token = localStorage.getItem('token')
      // console.log('-----', newState)
      break;
    case LOGION_OUT:
      newState.token = action.payload
      // console.log('-----', newState)
      break;
    case GET_USER_INFO:
      newState.userinfo = action.payload  
      break
    
    case GET_USER_LIST:
      newState.userlist = action.payload
      break
      
    default:

  }
  return newState
}
